package cn.sangyy.basic.controller;

import cn.sangyy.basic.dto.CodeInfoDto;
import cn.sangyy.basic.service.ICodeVerifyService;
import cn.sangyy.basic.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author SangYY
 * @date: 2023/06/01/15:04
 */
@RestController
@RequestMapping("/codeVerify")
public class CodeVerifyController {

    @Autowired
    private ICodeVerifyService codeVerifyService;

    /**
    * @author Sangyy
    * 获取图片验证码base64字符串
    */
    @GetMapping("/getImageCode/{key}")
    public AjaxResult getImageCode(@PathVariable("key") String key){
        String base64 = codeVerifyService.getBase64Str(key);
        return AjaxResult.me().setResultObj(base64);
    }

    /**
    * @author Sangyy
    * 注册获取手机验证码
    */
    @PostMapping("/sendSmsCode")
    public AjaxResult sendSmsCodeToRegister(@RequestBody CodeInfoDto codeInfoDto){
        codeVerifyService.sendSmsCode(codeInfoDto);
        return AjaxResult.me().setMessage("验证码已发送到你的手机短信上！");
    }

    /**
     * @author Sangyy
     * 登录获取手机验证码
     */
    @GetMapping("/sendSmsCodeToLogin")
    public AjaxResult sendSmsCodeToLogin(@RequestParam("phone") String phone){
        codeVerifyService.sendSmsCodeToLogin(phone);
        return AjaxResult.me().setMessage("验证码已发送到你的手机短信上！");
    }

    /**
     * @author Sangyy
     * 微信绑定手机发送验证码
     */
    @PostMapping("/sms/bind")
    public AjaxResult sendSmsCodeToWechat(@RequestBody Map<String,Object> params){
        codeVerifyService.sendSmsCodeToWechat(params);
        return AjaxResult.me().setMessage("验证码已发送到你的手机短信上！");
    }

}
